<?php
class Bootstrap extends Yaf_Bootstrap_Abstract {

    private $config;

    function _initConfig(Yaf_Dispatcher $dispatcher) {
        header("Content-Type:application/json; charset=utf-8");

        $this->config = Yaf_Application::app()->getConfig();
        //关闭controller自动加载模板
        Yaf_Dispatcher::getInstance()->autoRender(false);
        // core config import
        Yaf_Loader::import(BASE_PATH . '/conf/config.php');
        // 合并配置并保存起来
        Yaf_Registry::set('config', array_merge($this->config->toArray(), $config));
    }

    public function _initPlugin(Yaf_Dispatcher $dispatcher) {
        /* register a plugin */
        // $dispatcher->registerPlugin(new TestPlugin());
    }

    public function _initCommon()
    {
        Yaf_Loader::import(LIBRARY_PATH . '/Common.php'); //公用函数库
    }

    public function _initAutoload()
    {
        // Autoload 自动载入
        require APPLICATION_PATH . '/vendor/autoload.php';
    }

    /**
     * 加载配置错误处理方式
     */
    public function _initErrors()
    {
        if ($this->config->application->debug) {
            ob_start();
            error_reporting(-1);
            ini_set('display_errors', 'On');
        } else {
            error_reporting(0);
            ini_set('display_errors', 'Off');
        }

        register_shutdown_function('Debug::fatalError');
        set_error_handler('Debug::appError');
        set_exception_handler('Debug::appException');
    }
}
